package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.ChargeRefundEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 费用退费表Provider
 *
 * @author generator
 * @date 2020-05-12 14:24
 */
public class ChargeRefundProvider {

    /**
     * 增加ChargeRefund
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-12 14:24
     */
    public String insertChargeRefund(@Param("entity") ChargeRefundEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" charge_refund ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" charge_item_id ", " #{entity.chargeItemId,jdbcType=INTEGER} ");
                VALUES(" refund_charge ", " #{entity.refundCharge,jdbcType=DECIMAL} ");
                VALUES(" refund_minus_id ", " #{entity.refundMinusId,jdbcType=INTEGER} ");
                VALUES(" refund_new_id ", " #{entity.refundNewId,jdbcType=INTEGER} ");
                VALUES(" refund_time ", " #{entity.refundTime,jdbcType=TIMESTAMP} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改ChargeRefund
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-12 14:24
     */
    public String updateChargeRefund(@Param("entity") ChargeRefundEntity entity) {
        return new SQL() {
            {
                UPDATE(" charge_refund ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" charge_item_id = #{entity.chargeItemId,jdbcType=INTEGER} ");
                SET(" refund_charge = #{entity.refundCharge,jdbcType=DECIMAL} ");
                SET(" refund_minus_id = #{entity.refundMinusId,jdbcType=INTEGER} ");
                SET(" refund_new_id = #{entity.refundNewId,jdbcType=INTEGER} ");
                SET(" refund_time = #{entity.refundTime,jdbcType=TIMESTAMP} ");
                SET(" remark = #{entity.remark} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询ChargeRefund列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-12 14:24
     */
    public String listChargeRefund(@Param("entity") ChargeRefundEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,charge_item_id,refund_charge,refund_minus_id,refund_new_id,refund_time,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" charge_refund ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getChargeItemId() != null) {
                    WHERE(" charge_item_id = #{entity.chargeItemId,jdbcType=INTEGER} ");
                }

                if (entity.getRefundCharge() != null) {
                    WHERE(" refund_charge = #{entity.refundCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getRefundMinusId() != null) {
                    WHERE(" refund_minus_id = #{entity.refundMinusId,jdbcType=INTEGER} ");
                }

                if (entity.getRefundNewId() != null) {
                    WHERE(" refund_new_id = #{entity.refundNewId,jdbcType=INTEGER} ");
                }

                if (entity.getRefundTime() != null) {
                    WHERE(" refund_time = #{entity.refundTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}